<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <% include("../inc/list_css.html"){}%>
</head>
<body>
<div class="ibox ">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span>商品维护 </span>
            <span class="line">/</span>
            商品审核
        </div>
    </div>

    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-md-12">
                    <div   class="  "style="display: flex;align-items: center;justify-content: flex-end;width: 100%">
                        关键字:&nbsp;<input class="light-input" name="title_id" id="name" placeholder="商品名、产品类别" style="margin-right: 10px">
                        手机号:&nbsp;<input class="light-input" name="title_id" id="phone" placeholder="手机号请输全" style="">
                        <button class="hive-btn margin-left-5" id="search" onclick="searchList()">&nbsp;搜索&nbsp;</button>
                    </div>
                    <table data-toggle="table " id="table"
                           class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
                        <thead class="table-header">
                        <tr>
                            <th data-field="name" data-formatter="nameFormatter">名称</th>
                            <th data-field="categoryName">产品类别</th>
                            <!--<th data-field="productSn">编码</th>-->
                            <th data-field="price">销售价</th>
                            <th data-field="marketPrice">市场价</th>
                            <th data-field="isMarketable" data-formatter="boolFormatter">是否上架</th>
                            <!--<th data-field="isBest" data-formatter="boolFormatter">是否精品()</th>
                            <th data-field="isNew" data-formatter="boolFormatter">是否最新</th>-->
                            <th data-field="store" >库存</th>
                            <th data-field="createDate">创建日期</th>
                            <th data-field="isBestPlateform" data-formatter="boolFormatter">是否精品</th>
                            <th data-field="sortBestPlateform" data-formatter="sortBestPlateform" >精品排序</th>
                            <th data-field="sortCheapPlateform" data-formatter="boolFormatter">是否特惠</th>
                            <th data-field="sortCheapPlateform" data-formatter="sortCheapPlateform" >特惠排序</th>
                            <th data-field="productRebatePercent" data-formatter="productRebatePercent" >商品返利(%)</th>
                            <th data-field="productRebatePercentMoney" data-formatter="productRebatePercentMoney">返利金额</th>
                            <th data-field="checked" data-formatter="checkedFormatter">审核状态</th>
                            <th data-field="head" data-formatter="opFormatter" data-halign="center" data-align="center" data-width="120">操作</th>
                        </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>
<% include("../inc/list_js.html"){}%>
<script>
    function productRebatePercentMoney(value, row, index) {
        if(value==null){
            return '0';
        }else{
            return value;
        }
    }

    //商品返利
    function productRebatePercent(value, row, index) {
        return "<input onblur='updateProductRebatePercent(\""+row.id+"\",\""+value+"\",this)'  class='sort blurInput' id='" + row.id + "' value='" + (value == null ? '0' : value) + "' style='width: 25px;text-align: center' onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" onblur=\"this.value=this.value.replace(/\\D/g,'')\"/>";
    }
    function updateProductRebatePercent(id,origin,obj) {
        var productRebatePercent=obj.value;
        if(isNaN(productRebatePercent)){
            parent.layer.msg('请填写正整数!');
            return;
        }
        if(origin!=productRebatePercent){
            $.post('updateProductRebatePercent', {"id": id,"productRebatePercent":productRebatePercent}, function (e) {
                if (e.state == 'ok') {
                    parent.layer.msg('操作成功!');
                    $('#table').bootstrapTable('refresh');
                } else {
                    parent.layer.msg(e.info)
                }
            })
        }
    }
    //商品返利

    //精品排序
    function sortBestPlateform(value, row, index) {
        return "<input onblur='updateSortBestPlateform(\""+row.id+"\",\""+value+"\",this)'  class='sort blurInput' id='" + row.id + "' value='" + (value == null ? '0' : value) + "' style='width: 25px;text-align: center' onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" onblur=\"this.value=this.value.replace(/\\D/g,'')\"/>";
    }
    function updateSortBestPlateform(id,origin,obj) {
        var sortBestPlateform=obj.value;
        if(isNaN(sortBestPlateform)){
            parent.layer.msg('排序只能是数字!');
            return;
        }
        if(origin!=sortBestPlateform){
            $.post('updateSortBestPlateform', {"id": id,"sortBestPlateform":sortBestPlateform}, function (e) {
                if (e.state == 'ok') {
                    parent.layer.msg('操作成功!');
                } else {
                    parent.layer.msg(e.info)
                }
            })
        }
    }
    //精品排序

    //特惠排序
    function sortCheapPlateform(value, row, index) {
        return "<input onblur='updateSortCheapPlateform(\""+row.id+"\",\""+value+"\",this)'  class='sort blurInput' id='" + row.id + "' value='" + (value == null ? '0' : value) + "' style='width: 25px;text-align: center' onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" onblur=\"this.value=this.value.replace(/\\D/g,'')\"/>";
    }
    function updateSortCheapPlateform(id,origin,obj) {
        var sortCheapPlateform=obj.value;
        if(isNaN(sortCheapPlateform)){
            parent.layer.msg('排序只能是数字!');
            return;
        }
        if(origin!=sortCheapPlateform){
            $.post('updateSortCheapPlateform', {"id": id,"sortCheapPlateform":sortCheapPlateform}, function (e) {
                if (e.state == 'ok') {
                    parent.layer.msg('操作成功!');
                } else {
                    parent.layer.msg(e.info)
                }
            })
        }
    }
    //特惠排序


    function checkedFormatter(v) {
        if(v==0){
            return '未审核';
        }else if(v==1){
            return '审核通过';
        }else if(v==2){
            return '审核未通过';
        }else{
            return '未审核';
        }
    }

    function opFormatter(value, row, index) {

      var  html = '<a href="javascript:void(0)" class="icon-tab_details hive_icon color_normal" onclick="detail(\'' + row.id + '\',\''+row.shopId+'\');" data-toggle="tooltip" data-placement="top" title="商品详情"></a>';
        return html;
    }

    function nameFormatter(value, row, index) {//alert(row.isShowSku+" "+row.specificationtype);
        if (row.valuenames) {
            if(row.isShowSku)
                return value + "<span style='color: #00a0e9;margin-left: 5px'>[" + row.valuenames + "]</span>";
            else
                return value;
        } else
            return value;
    }



    function boolFormatter(v) {
        if (v)
            return '是';
        else
            return '否';
    }
    function searchList() {
        $('#table').bootstrapTable("refresh");
    }



    /**
     * 加载页面数据
	 * 1.function xxx(){}---这是函数声明
	 * 		function (){}---这也是函数声明，但由于没有给函数命名，所以叫匿名函数
	 * 		var str = function(){}---这是函数表达式
	 * 2.函数表达式后面可以加括号立即调用该函数
	 * 3.(function(){}).()---在匿名函数外加上括号，就可以将它转化为函数表达式。
	 * 		然后在加上括号，就可以立即调用该函数
     * */
    var table;
    (function () {

        table = $('#table').bootstrapTable({
            url: "ajaxlist",
            search: false,  //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            searchAlign: 'right',  //
            pagination: true,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            queryParamsType: '',
            sidePagination: 'server',//启用后台分页
            pageSize: 20,
            iconSize: 'outline',
            toolbar: '#add',
            queryParams: function queryParams(params) {
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    pageSize: params.pageSize,
                    pageNumber: params.pageNumber,
                    name: $("#name").val(),
                    phone: $("#phone").val(),
                };
                return temp;
            },
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },
            responseHandler: function (res) {
                return {
                    "rows": res.list,
                    "total": res.totalRow
                };
            },
            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            }
        });


        $('#add').on('click', function (e) {
            location.href = 'add';
        });

        $(".wrapper").tooltip({selector: "[data-toggle=tooltip]", container: "body"});


    })();


   function updateBlur(v,v2) {

       var v2 = $("#" + v).val();

        $.post('updateBlur',{"id":v,"order":v2},function (e) {
            if(e.state == "fail"){
                parent.layer.msg(e.info);
            }else{

                parent.layer.msg("修改成功!");
               // $('#table').bootstrapTable('refresh');
            }
        })


    }


    function detail(id,shopId) {
        window.location.href="detail?productId="+id+'&shopId='+shopId;
    }

</script>
</body>
</html>